//
//  STResponse.swift
//  Story
//
//  Created by 汤泽川 on 2019/4/2.
//  Copyright © 2019 汤泽川. All rights reserved.
//

import Foundation

class STResponse<T> {
    typealias ResponseCallBack = (_ error : STError?) -> Void
    typealias ResponseCallBackWithData = (_ data : T?, _ error : STError?) -> Void

    private var responseCallBack : ResponseCallBack?
    private var responseCallBackWithData : ResponseCallBackWithData?
    
    public func result(callBack : @escaping ResponseCallBack) {
        responseCallBack = callBack
    }
    public func result(callBackWithData : @escaping ResponseCallBackWithData) {
        responseCallBackWithData = callBackWithData
    }
    public func execute(_ data : T?, _ error : STError?) {
        if let responseCallBack = responseCallBack {
            responseCallBack(error)
        }
        if let responseCallBackWithData = responseCallBackWithData {
            responseCallBackWithData(data, error)
        }
    }
    init() {
        
    }
}
